//全部分类
const app = getApp(); //全局app
import { Classify } from 'classifyModel.js';
var classify = new Classify();

Page({
  //页面数据
  data: {
    top_class: [],
    class_list: [],
    baseurl: 'https://wukongweixiu.cn/',
    goodsId: '',
    on_class: '',
    content_height: 180,
    cate_style: 3, //新增分类样式
    remarke:'',
  },

  //加载执行
  onLoad: function (options) {
    var page = this;
    page._top_class();
    // 设置content高度
    wx.getSystemInfo({
      success: function (res) {
        page.setData({
          // second部分高度 = 窗口可使用高度 - 头部底部部分高度
          content_height: res.windowHeight - res.windowWidth / 750 * 120
        })
      }
    })
  },
  onShow: function () {
    var that = this
    var classid = 1;
    if (getApp().globalData.classid) {
      classid = getApp().globalData.classid;
    }
    that.setData({
      on_class: classid
    });
    this.getClassList(classid);
  },

  _top_class: function () {
    var that = this
    var data = classify.top_class(that.callBake);
  },
  callBake: function (res) {
    var that = this
    that.setData({
      top_class: res.data.data,
    })

  },

  //获取一级分类下的子分类列表
  getClassList: function (parent_id) {
    var that = this
    getApp().globalData.classid = parent_id;

    var data = classify.classList(that._callBake, parent_id);
  },

  _callBake: function (res) {
   console.log(res)
    var that = this
    if (res.data.code == 1) {
      that.setData({
        class_list: res.data.data,
        remarke:res.data.remarke,
      })
    }

  },


  //切换分类
  topclass: function (e) {
    var that = this
    that.getClassList(e.currentTarget.dataset.id);

    that.setData({
      on_class: e.currentTarget.dataset.id
    })
  },


  //前往商品分类列表
  title: function (event) {
    console.log(event.currentTarget.dataset.id)
    wx.navigateTo({
      url: '../detail/detail?id=' + event.currentTarget.dataset.id
    });
  },

  //客服回调
  customerService: function (e) { },

  //搜索
  // search: function (e) {
  //   var key = e.detail.value;
  //   wx.navigateTo({
  //     url: '../itemList/itemList?key=' + key
  //   });
  // },

  //跳转搜索
  searchNav: function () {
    wx.navigateTo({
      url: '../search/search'
    });
  },

  //页面隐藏执行
  onHide: function () {
    var that = this
    that.setData({
      key: ''
    });
  }
})